package com.cooper.tld;

import java.util.Collection;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

/**
 * 
* @Description: 
* @version: v1.0.0
* @author: tianlg
* @date: Jan 12, 2015 7:42:19 PM
*
* Modification History:
* Date         Author          Version            Description
*---------------------------------------------------------*
* Jan 12, 2015      tianlg          v1.0.0
 */
public class FunctionTag{
	
	public static <E> boolean contains(Collection<E> list, E obj){
		if(null == list || list.isEmpty()){
			return false;
		}
		return list.contains(obj);
	}
	
	public static <F, T> boolean containsKey(Map<F, T> map, F obj){
		if(null == map || map.isEmpty()){
			return false;
		}
		return map.containsKey(obj);
	}
	
	public static boolean in(Object value, Object... objects){
		for(Object arg: objects){
			if(value.equals(arg)){
				return true;
			}
		}
		return false;
	}
	
	public static String upperCase(String value){
		if(StringUtils.isEmpty(value)){
			return "";
		}
		return value.toUpperCase();
	}
	
	public static String lowerCase(String value){
		if(StringUtils.isEmpty(value)){
			return "";
		}
		return value.toLowerCase();
	}
	
	public static String desense(String value){
		StringBuffer buffer = new StringBuffer();
		if(StringUtils.isNotEmpty(value)){
			buffer.append(value.substring(0, value.length()-3));
		}
		buffer.append("***");
		return buffer.toString();
	}
	
	public static boolean stringContains(String source, String match){
		return source.contains(match);
	}
	
	public static String filterChinese(String s) {
		StringBuffer buffer = new StringBuffer();
		if (null == s || "".equals(s.trim()))
			return buffer.toString();
		for (int i = 0; i < s.length(); i++) {
			if (isChinese(s.charAt(i))){
				buffer.append(s.charAt(i));
			}
		}
		return buffer.toString();
	}
	public static String filterEnglish(String s) {
		StringBuffer buffer = new StringBuffer();
		if (null == s || "".equals(s.trim()))
			return buffer.toString();
		for (int i = 0; i < s.length(); i++) {
			char ch = s.charAt(i);
			if (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') ||
					' ' == ch || ('~' <= ch && ch <= '+')){
				buffer.append(s.charAt(i));
			}
		}
		return buffer.toString();
	}
	
	public static boolean isChinese(char a) {
		int v = (int) a;
		return (v >= 19968 && v <= 171941);
	}

	public static boolean containsChinese(String s) {
		if (null == s || "".equals(s.trim()))
			return false;
		for (int i = 0; i < s.length(); i++) {
			if (isChinese(s.charAt(i)))
				return true;
		}
		return false;
	}
}

